package com.iye.puretennis.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Author: Chuanbao on 2014/11/12.
 */
public class DBHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 5;
    private static final String DB_NAME = "puretennis.db";

    public static final String TABLE_USER_TOKEN = "usertoken";
    public static final String TABLE_USER = "user";
    public static final String TABLE_IDOLS= "idols";
    public static final String TABLE_MYCACHES = "mycaches";

    public DBHelper(Context context) {
        super(context, DB_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE usertoken (id integer primary key autoincrement, guid varchar(60), token varchar(60) unique)");
        db.execSQL("CREATE TABLE user (id integer primary key autoincrement, guid varchar(60) unique, name varchar(60) unique)");
        db.execSQL("CREATE TABLE idols (id integer primary key autoincrement, idols text)");
        db.execSQL("CREATE TABLE mycaches (id integer primary key autoincrement,userguid varchar(60), cachetype varchar(60),content text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists usertoken");
        db.execSQL("drop table if exists user");
        db.execSQL("drop table if exists idols");
        db.execSQL("drop table if exists mycaches");
        onCreate(db);
    }
}
